// 获取商品列表
let productListAll = ''
async function getProductList(pageNo){
    let data = await myPromise({
        method:'get',
        url:'http://api.yuguoxy.com/api/shop/list',
        data: {
            pageNo,
            pageSize:8
        }
    })
    if (data.resultCode == 1) {
        let product = data.resultCode == 1 ? data.resultInfo : []
        getProductListHtml(product.list)
    }
}
function getProductListHtml(list){
    let str = list.map(item =>{
        return `<li onclick="onProductDetail(${item.id})">
        <div class="proimg"><img src="${item.picture}" alt=""></div>
        <div class="protext">
            <span>${item.shop}</span>
            <span>淘宝</span>
            <span>包邮</span>
            <span>￥<span>${item.price}</span></span>
            <span>${item.oldprice}人已买</span>
        </div>
    </li>`
    })
    productListAll = productListAll + str
    $('#quanProduct ul').html(productListAll)
}
// 点击加载更多，获取更多商品
function getMore(){
    let pageNo = 1
    $('.productMore').on('click',function(){
        getProductList(++pageNo)
    })
}

//点击首页跳转到主界面index
function jumpToIndex(){
    $('#nav ul').on('click','li',function(){
        if($(this).text() == '首页'){
            location.href = './index.html'
        }
    })
}
//点击9块9跳转到9块9页面
function jumpTobaoyou(){
    $('#nav ul').on('click','li',function(){
        if($(this).text() == '9块9包邮'){
            location.href = './baoyou.html'
        }
    })
}
//点击商品列表跳转到对应商品详情页
function onProductDetail(id){
    location.href = './detail.html?id='+id
}

// 跳转至购物车
function jumpToShoppingCart(){
    $('#nav ul').on('click','li',function(){
        if($(this).text() == '购物车'){
            location.href = './shoppingCart.html'
        }
    })
}


jumpToShoppingCart()
getProductList()
getMore()
jumpToIndex()
jumpTobaoyou()